﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;
using Data;
namespace DAO
{
    public class TinhTrangBan_DAO
    {
        public static List<TinhTrangBan_DTO> SelectAll()
        {
            List<DTO.TinhTrangBan_DTO> result = new List<DTO.TinhTrangBan_DTO>();
            DataTable dt = Data.SQLAccess.ExecuteQuery("select *from TINH_TRANG_BAN");
            DTO.TinhTrangBan_DTO ttban;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ttban = new DTO.TinhTrangBan_DTO();
                ttban._Ma_Tinh_Trang = int.Parse(dt.Rows[i]["MA_TINH_TRANG"].ToString());
                ttban._Ten_Tinh_Trang = dt.Rows[i]["TEN_TINH_TRANG"].ToString();

                result.Add(ttban);
            }
            return result;
        }
        public static string Insert(DTO.TinhTrangBan_DTO ttban)
        {
            try
            {
                string str_sql = "insert into TINH_TRANG_BAN values("
                + ttban._Ma_Tinh_Trang + ",N'"
                + ttban._Ten_Tinh_Trang + "'"
                + ")";
                DataTable dt = Data.SQLAccess.ExecuteQuery(str_sql);
                return "true";
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
        public static string Delete(TinhTrangBan_DTO ttban)
        {
            try
            {
                return "true";
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
    }
}
